import request from '@/router/axios';

export const getList = (current, size, params) => {
  return request({
    url: '/api/mes-product/workorderPlan/page-workOrder-with-process-and-plan',
    method: 'get',
    params: {
      ...params,
      current,
      size
    }
  });
};

// 查询排程列表数据
export const getPlanInfoList = ({ workOrderId, queryTimeStart, queryTimeEnd }) => {
  return request({
    url: `api/mes-product/workorderPlan/plan-info?workOrderId=${workOrderId}&queryTimeStart=${queryTimeStart}&queryTimeEnd=${queryTimeEnd}`,
    // url: `api/mes-product/workorderPlan/plan-info?workOrderId=${workOrderId}&queryTimeStart=2024-09-13%2010%3A13%3A07&queryTimeEnd=2024-09-18%2010%3A13%3A07`,
    method: 'get'
  });
};

// 查询产线UPH和日剩余工时数据
export const getPlanLineInfo = (productPartId, lineId, queryTimeStart, queryTimeEnd) => {
  return request({
    url: '/api/mes-product/workorderPlan/line-plan-info',
    method: 'get',
    params: {
      productPartId,
      queryTimeStart,
      queryTimeEnd,
      lineId
    }
  });
};

// 派工
export const submitPlan = (data) => {
  return request({
    url: '/api/mes-product/workorderPlan/submit-plan',
    method: 'post',
    data
  });
};

// 撤销
export const revokePlan = (data) => {
  return request({
    url: '/api/mes-product/workorderPlan/revoke-plan',
    method: 'post',
    data
  });
};

// 查询产品工段
export const getProductLineSection = () => {
  return request({
    url: '/api/mes-product/work-section/all-section',
    method: 'get'
  });
};

// 获取排程备注
export const getOperationLog = (bizCode) => {
  return request({
    url: '/api/mes-admin/operationLog/detail',
    method: 'get',
    params: {
      bizCode,
      title: 'APS_WORK_ORDER_PLAN'
    }
  });
};

// 获取排程详情操作记录
export const getOperationList = (objCode) => {
  return request({
    url: '/api/mes-admin/operationLog/list',
    method: 'get',
    params: {
      objCode,
      title: 'APS_WORK_ORDER_PLAN'
    }
  });
};

// 根据workOrderId查询排程列表时间区间范围
export const getApsDateRangeByWorkOrderId = (workOrderId) => {
  return request({
    url: '/api/mes-product/productionline/init-aps-date-range',
    method: 'get',
    params: {
      workOrderId
    }
  });
};

// （产线资源使用）根据workOrderId查询工段产线Cascades级联
export const getProductLineSectionByWp = (workOrderId, partNo) => {
  return request({
    url: '/api/mes-product/apsworkorderplan/init-section-product-line-by-wp',
    method: 'get',
    params: {
      workOrderId,
      partNo
    }
  });
};

// 查询工单排程计划列表
export const getApsPlan = (workOrderId) => {
  return request({
    url: '/api/mes-product/apsworkorderplan/list-aps-work-order-plan',
    method: 'get',
    params: {
      workOrderId
    }
  });
};

// 预览APS资源列表信息
export const getAllApsResourcePreview = (data) => {
  return request({
    url: '/api/mes-product/apsworkorderplan/list-aps-resource-preview',
    method: 'post',
    data
  });
};

// 计算APS排程
export const calculateApsPlan = (data) => {
  return request({
    url: '/api/mes-product/apsworkorderplan/calculate-aps-plan',
    method: 'post',
    data
  });
};

// 保存草稿
export const apsSubmit = (data) => {
  return request({
    url: '/api/mes-product/apsworkorderplan/submit',
    method: 'post',
    data
  });
};

// 派工
export const dispatchWorkOrder = (workOrderId, continueStatus = false) => {
  return request({
    url: '/api/mes-product/apsworkorderplan/dispatch-work-order',
    method: 'get',
    params: {
      workOrderId,
      continueStatus
    }
  });
};

// 获取产线资源
export const getLineResource = (params) => {
  return request({
    url: '/api/mes-product/line-resource/page-specially',
    method: 'get',
    params: params
  });
};

// 计划排程 => 获取产线资源
export const getLineResourceByProductPart = (productPartId, lineId = '', queryTimeStart, queryTimeEnd) => {
  return request({
    url: '/api/mes-product/line-resource/productPartInfo',
    method: 'get',
    params: {
      productPartId,
      queryTimeStart,
      queryTimeEnd,
      lineId
    }
  });
};
